$(function(){
	$('.input').focus(function(){
//	判断input是否为空
		$('.error_msg').text('');
	})
	$('.input').bind('input propertychange',function(){
		if($("#userPwd").val() != ""){
			$("#button").removeAttr("disabled");
			$("#button").css("background","#FF5000");
		}else{
			$("#button").attr("disabled","disabled");
			$("#button").css("background","#999");
		}
	})
	$('.show_pwd').hide();
	$('#userPwd').bind('input propertychange',function(){
		if($(this).val()!=''){
			$('.show_pwd').show();
		}else{
			$('.show_pwd').hide();
		}
	})
	$('.show_pwd').click(function(){
		$('#userPwd').attr('type',$('form .pwd input').attr('type')=='password'?'text':'password');	
	})
	//	密码规则验证函数
	function pwdCheck(){
		var userPwd = $('#userPwd').val();
		var pattern = /(?:\d.*_)|(?:_.*\d)|(?:[A-Za-z].*_)|(?:_.*[A-Za-z])|(?:[A-Za-z].*\d)|(?:\d.*[A-Za-z])/;
		if(userPwd.length<6 || userPwd.length>18){
			$('.error_msg').text('*密码必须大于6位，小于18位');
			return false;
		}else if(!pattern.test(userPwd)){
			$('.error_msg').text('*密码至少包含数字、字母、下划线中的两个');
			return false;
		}else{
			return true;
		}
	}
//	重置密码
	//	注册提交
	$('.reset_button').click(function(){
		if(pwdCheck()){					
			var userMobile = $.cookie(userMobile).userMobile;
//			var userPwd = $('#userPwd').val();
			console.log(userMobile)
//			console.log(userPwd)
			var key = CryptoJS.enc.Utf8.parse(constans.resetpwdSecKey);
	 		var srcs = CryptoJS.enc.Utf8.parse($('#userPwd').val());
	 		var encrypted = CryptoJS.AES.encrypt(srcs, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7}).toString();
			var userPwd = encrypted;
			var data = {userMobile:userMobile,userPwd:userPwd};
			console.log(data);
			$.post(constans.globalUrl+'/user/resetpwd',data,function(data){
				console.log(data);
				if(data.code == 'SUCCESS'){
					console.log('密码更改成功')
				alert('密码更改成功');
				location.href = constans.htmlUrl+'/html/login.html';
				}
				else{				
					$('.error_msg').text(data.message);
				}
			})
		}
	})
	
})